var crypto = require('crypto');
var underscore = require('underscore');
var env = require("../env.json");


/**
 * 获取签名
 * @param postobj
 * @returns {string|*}
 */
function getSign(postobj) {
    var pobj = underscore.clone(postobj);
    pobj.skey = '~*DaxW*$ETSCwPqTWmKe9j*u(BV4it5N';
    arr = underscore.values(pobj);
    arr = arr.sort();
    var str = arr.join('');
    return crypto.createHash('sha256').update(str).digest().toString('hex');
}

/**
 * 获取环境 dev: 开发环境  stage: 准生产  prod: 生产环境
 * @returns {string}
 */
function getEnv() {
    return env.env;
}

/**
 * 获取输入变量 {v} , 判断,如输入变量 {v} 为空,则返回默认值 {d}
 * @param v
 * @param d
 * @returns {*}
 */
function getInput(v, d){
    return v ? v : d;
}

exports.getSign = getSign;
exports.getEnv = getEnv;
exports.getInput = getInput;